﻿using System.Xml.Serialization;
using Core.Domain.Entities;
using Core.Domain.Enums;

namespace DataXml.CommunityFiles
{
  [XmlRoot("Person")]
  public class XmlPerson
  {
    #region XmlAgeGroup enum

    public enum XmlAgeGroup
    {
      Adult,
      Youth,
      Child,
      PreYouth
    }

    #endregion

    #region XmlVoted enum

    public enum XmlVoted
    {
      No,
      VotedInPerson,
      DroppedOff,
      Mailed
    }

    #endregion

    #region XmlVoterEligibility enum

    public enum XmlVoterEligibility
    {
      Eligible,
      Unknown,
      Ineligible
    }

    #endregion

    [XmlAttribute(AttributeName = "Voted")]
    public XmlVoted Voted { get; set; }

    [XmlAttribute(AttributeName = "VotingEligibility")]
    public XmlVoterEligibility VotingEligibility { get; set; }

    [XmlAttribute(AttributeName = "BahaiId")]
    public string BahaiId { get; set; }

    [XmlAttribute(AttributeName = "FName")]
    public string FirstName { get; set; }

    [XmlAttribute(AttributeName = "LName")]
    public string LastName { get; set; }

    [XmlAttribute(AttributeName = "AKAName")]
    public string AKAName { get; set; }

    [XmlAttribute(AttributeName = "AgeGroup")]
    public XmlAgeGroup AgeGroup { get; set; }

    ///<summary>Map to core Person</summary>
    ///<returns></returns>
    public Person AsPerson()
    {
      return new Person
               {
                     AgeGroup = Convert(AgeGroup),
                     BahaiId = BahaiId,
                     FirstName = FirstName,
                     LastName = LastName,
                     OtherFirstNames = AKAName
               };
    }

    private AgeGroup Convert(XmlAgeGroup xmlAgeGroup)
    {
      switch (xmlAgeGroup)
      {
        case XmlAgeGroup.Adult:
          return Core.Domain.Enums.AgeGroup.Adult;
        case XmlAgeGroup.Youth:
          return Core.Domain.Enums.AgeGroup.Youth;
        case XmlAgeGroup.PreYouth:
          return Core.Domain.Enums.AgeGroup.JuniorYouth;
        case XmlAgeGroup.Child:
          return Core.Domain.Enums.AgeGroup.Child;
        default:
          return Core.Domain.Enums.AgeGroup.Unknown;
      }
    }
  }
}